import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import '../../resources/kq_theme_colors.dart';


/// 标签控件
///
/// 圆角边框(实线或虚线) + 文字
///
/// @author 周卓
///
class KqTagView extends StatelessWidget {
  /// 文字
  final String text;

  /// 字体大小，默认14
  final double? fontSize;

  /// 内边距
  final EdgeInsets? padding;

  /// 是否虚线，默认false
  final bool dashLine;

  /// 文字颜色，默认黄色
  final Color textColor;

  /// 边框颜色，默认黄色
  final Color borderColor;

  /// 背景颜色，默认透明
  final Color backgroundColor;

  /// 圆角，默认3
  final double? radius;

  /// 最大宽度，默认68
  final double? maxWidth;

  const KqTagView(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.maxWidth,
      this.textColor = KqThemeColors.textYellow,
      this.borderColor = KqThemeColors.textYellow,
      this.backgroundColor = KqThemeColors.bgTransparent,
      this.radius})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return dashLine
        ? DottedBorder(
            borderType: BorderType.RRect,
            strokeWidth: 0.5,
            padding: const EdgeInsets.all(0.5),
            color: borderColor,
            borderPadding: const EdgeInsets.only(bottom: 0.5),
            radius: Radius.circular(radius ?? 2.r),
            child: ClipRRect(
              borderRadius: BorderRadius.all(Radius.circular(radius ?? 2.r)),
              child: ConstrainedBox(
                constraints: BoxConstraints(maxWidth: maxWidth ?? 68.r),
                child: Container(
                  color: backgroundColor,
                  padding: padding ??
                      EdgeInsets.symmetric(horizontal: 3.5.r, vertical: 2.5.r),
                  child: Text(
                    text,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        fontSize: fontSize ?? 12.sp, color: textColor),
                  ),
                ),
              ),
            ),
          )
        : ConstrainedBox(
            constraints: BoxConstraints(maxWidth: maxWidth ?? 68.r),
            child: Container(
              padding: padding ??
                  EdgeInsets.symmetric(horizontal: 3.5.r, vertical: 2.5.r),
              decoration: BoxDecoration(
                  color: backgroundColor,
                  borderRadius:
                      BorderRadius.all(Radius.circular(radius ?? 2.r)),
                  border: Border.all(width: 0.5, color: borderColor)),
              child: Text(
                text,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(fontSize: fontSize ?? 12.sp, color: textColor),
              ),
            ),
          );
  }
}
